package generics;

import net.mindview.util.Generator;

import java.util.*;

/**
 * @author 杨宇
 * @version 1.0 2016/11/1
 */
public class E18_Ocean {

    public static void eat(BigFish b, LittleFish l) {
        System.out.println(b + " eat " + l);
    }

    public static void main(String[] args) {
        Random rand = new Random(47);
        Queue<LittleFish> line = new LinkedList<>();
        Generators.fill(line, LittleFish.generator, 15);
        List<BigFish> tellers = new ArrayList<>();
        Generators.fill(tellers, BigFish.generator(), 4);
        for (LittleFish c : line)
            eat(tellers.get(rand.nextInt(tellers.size())), c);
    }
}

class BigFish {
    private static int counter = 0;
    private final int id = ++counter;

    private BigFish() {
    }

    public static Generator<BigFish> generator() {
        return new Generator<BigFish>() {
            @Override
            public BigFish next() {
                return new BigFish();
            }
        };
    }

    @Override
    public String toString() {
        return "BigFish-" + id;
    }
}

class LittleFish {
    private static int counter = 0;
    private final int id = ++counter;

    private LittleFish() {
    }

    public static Generator<LittleFish> generator = new Generator<LittleFish>() {
        @Override
        public LittleFish next() {
            return new LittleFish();
        }
    };

    @Override
    public String toString() {
        return "LittleFish-" + id;
    }

}
